import MySQLdb

conn = MySQLdb.connect(host='47.104.31.138', port=3306,
                       user='hellokitty', passwd='Hellokitty.618',
                       db='hrs', charset='utf8')
try:
    with conn.cursor(MySQLdb.cursors.DictCursor) as cursor:
        cursor.execute('select dno as no, dname as name, dloc as loc from tb_dept')
        for dept in cursor.fetchall():
            print(dept)
finally:
    conn.close()
